package com.toulezu.test.transaction;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {

    private boolean flag = true;

    @Transactional(propagation = Propagation.REQUIRED)
    public int addUser() {
        System.out.println(1 / 0);
        return 1;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public int addUserCycle() {
        if (flag) {
            flag = false;

            try {
                addUserCycle();
            } catch (Exception e) {
            }
            System.out.println(1 / 0);
        }

        return 1;
    }
}
